<?php
require_once '../sever/json.php';
require_once '../sever/dbhelper.php';
//从登陆页面获取用户输入的用户名以及密码,进行验证

$username=empty($_REQUEST['username'])?'':$_REQUEST['username'];
$password=empty($_REQUEST['password'])?'':$_REQUEST['password'];

if (empty($username)){
    Responce::json('-3','请输入用户名');
}
if (empty($password)){
    Responce::json('-3','请输入密码');
}

$pdo=DB::getInstance()->connect();

$stmt = $pdo->query("select * from user where username='$username'"); //返回一个PDOStatement对象

$user = $stmt->fetch();
if (empty($user)){
    Responce::json('-1','用户不存在');
}
if ($user['password']==$password){
    Responce::json('200','登录成功',$user);
    session_start();
    $_SESSION['username']=$username;
}else{
    Responce::json('-2','密码不正确');
}




